package com.green.business.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.green.business.domain.Goods;
import com.green.business.vo.MemberVo;
import com.green.system.common.Constant;
import com.green.system.common.DataGridView;
import com.green.system.domain.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.green.business.domain.Member;
import com.green.business.mapper.MemberMapper;
import com.green.business.service.MemberService;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * @Author: Green
 * @Date: 2021/11/30/10:37
 * @Description: 
 */


@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService{
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public DataGridView queryAllMember(MemberVo memberVo) {
        IPage<Member> page = new Page<>(memberVo.getPage(),memberVo.getLimit());
        QueryWrapper<Member> qw = new QueryWrapper<>();
        qw.like(StringUtils.isNotBlank(memberVo.getName()),"name",memberVo.getName());
        qw.like(StringUtils.isNotBlank(memberVo.getPhone()),"phone",memberVo.getPhone());

        this.memberMapper.selectPage(page,qw);
        return new DataGridView(page.getTotal(),page.getRecords());
    }

    @Override
    public Member saveMember(Member member) {
        this.memberMapper.insert(member);
        return member;
    }

    @Override
    public Member updateMember(Member member) {
//        Member selectById = this.memberMapper.selectById(member.getCardid());
//        BeanUtil.copyProperties(member,selectById, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
        this.memberMapper.updateById(member);
        return member;
    }

    @Override
    public Member queryPhoneMember(String phone) {
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(phone),"phone",phone);

        return this.memberMapper.selectOne(queryWrapper);
    }


    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

}
